package com.lab;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class MyListAdapter extends ArrayAdapter<Person> {

	List<Person> persons;

	public MyListAdapter(Context context, int textViewResourceId,
			List<Person> objects) {
		super(context, textViewResourceId, objects);
		persons = objects;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Person p = persons.get(position);
		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
					Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.list_item2, null);
		}
		if (p != null) {
			TextView tt = (TextView) v.findViewById(R.id.textView1);
			TextView bt = (TextView) v.findViewById(R.id.textView2);

			if (tt != null) {
				tt.setText(p.fname);
			}
			if (bt != null) {
				bt.setText(p.lname);
			}
		}
		return v;
	}

}